<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Vue 前端路由初体验</title>
</head>
<body>
<div id="app">
    <!--  router-link 在使用过程中，可以实现在不发生网络情况和刷新页面的情况下，实现页面的切花  -->
    <router-link to="/">首页</router-link>
    <router-link to="/about">关于</router-link>
    <router-view></router-view>
</div>

<script type="module">
    import {createApp} from "../../../../js/vue.esm-browser.js";
    import {createRouter, createWebHashHistory} from "../../../../js/vue-router.esm-browser.js";

    // step 1.定义组件
    const Home = {template: "<h1>Home Page</h1>"}

    const About = {template: "<h1>About Page</h1>"}

    // step 2.定义组件和 URL 的对应关系
    const routes = [
        {
            path: "/",
            component: Home,
        },
        {
            path: "/about",
            component: About,
        },
    ]


    const router = createRouter(
        {
            history: createWebHashHistory(),
            routes: routes,
        }
    )

    let app = createApp(
        {
            setup() {
                return {}
            }
        }
    )

    app.use(router)
    app.mount("#app")
</script>
</body>
</html>